#include <iostream>
#include "Record.h"
#include "Schema.h"
#include "DBFile.h"
#include <stdlib.h>

#include "File.h"
extern struct AndList *final;

extern "C" {
	int yyparse(void);   // defined in y.tab.c
}


int main(){
	Schema schema("catalog","lineitem");
	Record record;
	DBFile dbfile;
	int i ;
	Page page;
	
	dbfile.Create("./lineitem.db", heap, NULL);
	dbfile.Load(schema, "./10M/lineitem.tbl");
	
	dbfile.Open("./lineitem.db");
	//FILE * file = fopen ( "./10M/lineitem.tbl", "r");
	
	
	//fclose(file);
	
	//dbfile.Close();

	//dbfile.Open("./lineitem.db");
	
				
	//dbfile.Close();
	
	/*print last page*/
	/*File lineitem;
	lineitem.Open(1, "./lineitem.db");
	cout << "total pages in the table : "  << lineitem.GetLength()-1 << endl;
	lineitem.GetPage(&page,0);
	while ( page.GetFirst(&record) )
	{
		record.Print(&schema);
		
	}*/
	
	
	
	/*while( dbfile.GetNext( record ) )
	{
		record.Print(&schema);
	}*/
		
	
	/*int countPage=0;
	for( i = 0 ; i < 101; i++ ){
			cout << "fetching page: " << countPage++ << endl;
			lineitem.GetPage(&page, i);
	}
	
	
	//page.EmptyItOut();
	fclose(file);	
	*/
	
	
	//File lineitem;
	//lineitem.Open(1, "./lineitem.db");
	//cout << "total pages in a empty db: " << lineitem.GetLength() << endl;
	
	/*cout << "Enter in your CNF: ";
  	if (yyparse() != 0) {
		cout << "Can't parse your CNF.\n";
		exit (1);
	}
	
	CNF myComparison;
	Record literal,temp;
	myComparison.GrowFromParseTree (final, &schema, record);
	myComparison.Print ();
	
	//for  (int i=0;i < 10000 ; i++ )
	//{
	while(dbfile.GetNext(temp,myComparison,record)){
		temp.Print(&schema);
	}*/
	
	
	dbfile.Close();
	return 0;
}
